package com.LeeCode;

/**
 * 分割字符串的最大得分
 */

public class Code1422 {
    public static void main(String[] args) {

    }

    public int maxScore(String s) {
        int n = s.length();
        int[] prefix = new int[n + 1];
        int[] suffix = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            prefix[i] = prefix[i - 1] + (s.charAt(i - 1) == '0' ? 1 : 0);
        }
        for (int i = n - 1; i >= 0; i--) {
            suffix[i] = suffix[i + 1] + (s.charAt(i) == '1' ? 1 : 0);
        }
        int max = 0;
        for (int i = 1; i < n; i++) {
            max = Math.max(max, prefix[i] + suffix[i]);
        }
        return max;
    }
}
